home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-1.iso / games / ted5.zip / IGRABSRC.ZIP / IGRAB.BAK < prev    next >
Text File  |  1993-02-04  |  7KB  |  238 lines

  1. #include <memory.h>
  2. #include <io.h>
  3. #include <dos.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <conio.h>
  7. #include <string.h>
  8. #include <alloc.h>
  9. #include <bios.h>
  10. #include <fcntl.h>
  11. #include <time.h>
  12.  
  13. #include "xms.h"
  14.  
  15. #define VERSION        "0.40"
  16. #define TITLESTR    "IGRAB v"VERSION" by John Romero (C) 1991 Id Software\n\r"
  17. #define NUMBITARRAY    600
  18. #define CHKNAMELEN    20
  19. #define NAMELEN        32
  20. #define FNAMELEN    13
  21.  
  22. #define BUFFERSIZE    0x14000L
  23. #define MAXCOMPSIZE    0x14000L
  24.  
  25. #define BUFFER1SIZE    0x1d000L    // for REALLY huge EGA screens
  26. #define MAXCOMP1SIZE    0x1d000L
  27.  
  28. #define MAXFONT        10
  29. #define MAXPICS        200
  30. #define MAXSPRITES    800
  31. #define MAXGRID8    19*12
  32. #define MAXGRID16    12*8
  33. #define MAXGRID32    7*4
  34. #define MAXALT8        36*21
  35. #define MAXALT16    18*12
  36. #define MAXALT32    9*6
  37. #define GRID8H        19
  38. #define ALT8H        36
  39. #define GRID16H        12
  40. #define ALT16H        18
  41. #define GRID32H        7
  42. #define ALT32H        9
  43. #define MAXOFFS        6000
  44.  
  45. #define GCindex        0x3ce
  46. #define GCmode        5
  47. #define GCreadmap    4
  48. #define SCindex        0x3c4
  49. #define SCmapmask    2
  50.  
  51. //
  52. // TYPEDEFS
  53. //
  54. typedef struct
  55. {
  56.   unsigned bit0,bit1;    // 0-255 is a character, > is a pointer to a node
  57. } huffnode;
  58.  
  59. typedef struct { unsigned width,height;
  60.            } PicStruct;
  61.  
  62.  
  63. typedef struct { int width,height;
  64.          int orgx,orgy;
  65.          int xl,yl,xh,yh;
  66.          int shifts;
  67.            } SprStruct;
  68.  
  69. typedef struct { int width;
  70.          int height;
  71.          int planes;
  72.            } LBMtype;
  73.  
  74. //
  75. // STRUCTURE OF THE "GFXINFO?.EXT" FILE
  76. //
  77. typedef struct {
  78.          int num8,num8m,num16,num16m,num32,num32m;
  79.          int off8,off8m,off16,off16m,off32,off32m;
  80.          int numpics,numpicm,numsprites;
  81.          int offpic,offpicm,offsprites;
  82.          int offpicstr,offpicmstr,offsprstr;
  83.          int numexterns,offexterns;
  84.            } InfoStruct;
  85.  
  86. typedef enum {FONTTYPE,FONTMTYPE,TILE8TYPE,ALT8TYPE,TILE8MTYPE,ALT8MTYPE,
  87.       TILE16TYPE,ALT16TYPE,TILE16MTYPE,ALT16MTYPE,TILE32TYPE,ALT32TYPE,
  88.       TILE32MTYPE,ALT32MTYPE,PICTYPE,PICMTYPE,SPRITETYPE }grabtype;
  89.  
  90. typedef enum {FONT,FONTM,TILE8,TILE8M,TILE16,TILE16M,TILE32,TILE32M,
  91.           PIC,PICM,SPRITE}datatype;
  92.  
  93. typedef enum {CGA,EGA,VGA,SGA}graphtype;
  94.  
  95. typedef struct { unsigned num,graphlen[4];
  96.          long offset; } DataStruct;
  97.  
  98. typedef struct { unsigned y,height; } OptStruct;
  99.  
  100. typedef enum {DATA,CODE,FARDATA} segtype;    // FOR MAKEOBJ ONLY
  101.  
  102. //
  103. // PROTOTYPES
  104. //
  105.  
  106. //
  107. // IGRAB
  108. //
  109. char huge *LoadLBM(char *filename,LBMtype *);
  110. char CharEdgeCheck(int x,int y);
  111. int MakeOBJ(char *filename,char *destfilename,char *public,segtype whichseg,char *farname);
  112. void CheckBuffer(void);
  113. void DeleteTmpFiles(void);
  114. void AddDataToFile(char *filename);
  115. void FlushData(void);
  116. void videomode(int planes);
  117. void SaveFile(char *filename,char huge *buffer, long size,long offset);
  118. unsigned long LoadFile(char *filename,char huge *buffer,long offset,long size);
  119. void errout(char *string);
  120. void settext(void);
  121.  
  122. //
  123. // GRABCGA
  124. //
  125. void CGAgrab(int x,int y,int width,int height,unsigned offset);
  126. void DoCGAblit(int x,int y,int width,int height);
  127. void CGAblit(int x,int y,int width,int height,char huge *buffer);
  128. void CGAMgrab(int x,int y,int width,int height,unsigned offset,int optimize);
  129. void DoCGAMblit(int x,int y,int width,int height,int yadd,int hadd);
  130. void CGAMblit(int x,int y,int width,int height,char huge *buffer);
  131.  
  132. //
  133. // GRABEGA
  134. //
  135. void EGAgrab(int x,int y,int width,int height,long offset);
  136. void DoEGAblit(int x,int y,int width,int height);
  137. void EGAblit(int x,int y,int width,int height,char huge *buffer);
  138. void EGAMgrab(int x,int y,int width,int height,long offset,int optimize);
  139. void DoEGAMblit(int x,int y,int width,int height,int yadd,int hadd);
  140. void EGAMblit(int x,int y,int width,int height,char huge *buffer);
  141.  
  142. //
  143. // GRABVGA
  144. //
  145. void VGAgrab(int x,int y,int width,int height,unsigned offset);
  146. void DoVGAblit(int x,int y,int width,int height);
  147. void VGAblit(int x,int y,int width,int height,char huge *buffer);
  148. void VGAMgrab(int x,int y,int width,int height,unsigned offset,int optimize);
  149. void DoVGAMblit(int x,int y,int width,int height,int yadd,int hadd);
  150. void VGAMblit(int x,int y,int width,int height,char huge *buffer);
  151.  
  152. //
  153. // FINISH
  154. //
  155. void CreateHeaders(void);
  156. void FinishUp(void);
  157. void FindType(char *string);
  158. void LoadKeyword(char *string,int grabbed);
  159. void FreeXMSbuffs(int *handle1,int *handle2,char *filename,long start,long size);
  160. void DispStatusScreen(void);
  161. int CheckXMSamount(char *filename,int *handle1,int *handle2);
  162. long filelen(char *filename);
  163. void CompressData(void);
  164. void CompressFonts(void);
  165. void CompressPics(void);
  166. void CompressSprites(void);
  167. void Compress8(void);
  168. void Compress16(void);
  169. void Compress32(void);
  170. void CompressMisc(void);
  171. void SetupFinish(void);
  172. void CreateOffsets(void);
  173. void CompressSpecial(void);
  174. void CreateGraphFiles(void);
  175. void CreateOBJs(void);
  176. void UpdateWindow(void);
  177. void VL_MungePic (unsigned char far *source, unsigned width, unsigned height);
  178.  
  179. //
  180. // DOGRAB
  181. //
  182. void GrabFont(grabtype type);
  183. void DoGrab(int x,int y,int width,int height,unsigned offset);
  184. void DoMGrab(int x,int y,int width,int height,unsigned offset,int opt);
  185. void DoMBlit(int x,int y,int width,int height,int yadd,int hadd);
  186. void DoBlit(int x,int y,int width,int height);
  187. void GrabTile(grabtype type);
  188. void GrabPics(grabtype type);
  189. void GrabSprites(void);
  190.  
  191. //
  192. // JHUFF
  193. //
  194. void CountBytes (unsigned char huge *start, long length);
  195. long HuffCompress (unsigned char huge *source, long length,
  196.   unsigned char huge *dest);
  197.  
  198. //
  199. // VARS
  200. //
  201. extern time_t tblock;
  202. extern LBMtype CurrentLBM;
  203. extern PicStruct far *PicTable,far *PicmTable;
  204. extern SprStruct SpriteTable[MAXSPRITES];
  205. extern FILE *fp;
  206. extern grabtype type;
  207. extern graphtype gmode;
  208. extern DataStruct Data[11];
  209. extern OptStruct Optimum;
  210.  
  211. extern char typestr[5];
  212.  
  213. extern char picname[64],huge *Sparse;
  214.  
  215. extern char huge *PicNames,huge *SpriteNames,huge *PicMNames,
  216.         huge *ChunkNames,huge *MiscNames,huge *MiscFNames;
  217.  
  218. extern unsigned char format[2], scriptname[64],dest[13],string[80],ext[10],huge *lbmscreen,
  219.      huge *databuffer,huge *maskscreen,ScreenColor,huge *T8bit,huge *T16bit,huge *T32bit,
  220.      typelist[17][10],path[64],NumMisc;
  221. extern long offset,size,fsize,tile8off,tile8moff,tile16off,tile16moff,
  222.      tile32off,tile32moff,picoff,picmoff,spriteoff,fontoff,fontmoff,
  223.      FontOffs[MAXFONT],far *PicOffs,SpriteOffs[MAXSPRITES],FontMOffs[MAXFONT],
  224.      far *PicMOffs,bufmax,comp_size;
  225. extern unsigned begin,j,i,gotstr,frac,temp,keycheck,compress,
  226.      end,gottiles,globalx,globaly,globalmaxh,nostacking,noshow,shifts,
  227.      fastgrab,totalobjects,leavetmp,cmpt8,genobj,ChunkStart[MAXSPRITES/8],
  228.      ChunkEnd[MAXSPRITES/8],whichchunk,ChunkType[MAXSPRITES/8],bit,
  229.      T8whichbit,T16whichbit,T32whichbit,setbit,lumpactive,SkipToStart,
  230.      Do4offs,ModeX,PicAmount;
  231.  
  232. extern char far SCREEN;
  233. extern int handle;
  234.  
  235. extern long counts[256];
  236. extern unsigned long huffstring[256];
  237. extern huffnode nodearray[256];    // 256 nodes is worst case
  238.